package edu.ctbu.datajpa1.service;

import edu.ctbu.datajpa1.dao.StudentRepository;
import edu.ctbu.datajpa1.domain.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentService {

    @Autowired

    private StudentRepository studentRepository;

    public List<Student> getAll(){



        return studentRepository.findAll();
    }

    /**
     * 按id取数据
     * @param id
     * @return 取到的学生信息
     */
    public Student getById(Integer id){
        return studentRepository.findById(id).get();
    }



    public List<Student> findByName(String name){

       return  studentRepository.findByName(name);
    }

}
